package tetrisgui;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

import tetrismain.Board;
import tetrismain.IPiece;
import tetrismain.JPiece;
import tetrismain.OPiece;
import tetrismain.Piece;

public class Tet {
	Board j = new Board();
	JFrame main = new JFrame();
	public  void start() {
		BoardGui g = new BoardGui(j);
		main.setBackground(Color.BLACK);
		g.addKeyListener(new TetrisListener());
		main.addKeyListener(new TetrisListener());
		main.add(g);
		main.setSize(new Dimension(600, 600));
		main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		main.setVisible(true);
	}
	public static void main(String[] arg){
		Tet t = new Tet();
		t.start();
	}
	private class TetrisListener implements KeyListener{
		private void getAction(KeyEvent arg0){
			if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
				j.moveDown();
				main.repaint();
			}else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
				j.moveLeft();
				main.repaint();
			}else if (arg0.getKeyCode()==KeyEvent.VK_RIGHT){
				j.moveRight();
				main.repaint();
			}else if(arg0.getKeyCode() == KeyEvent.VK_UP){
				j.rotate();
				main.repaint();
			}
		}
		@Override
		public void keyPressed(KeyEvent arg0) {
			getAction(arg0);
		}

		@Override
		public void keyReleased(KeyEvent arg0) {
		}

		@Override
		public void keyTyped(KeyEvent arg0) {
			
		}
		
	}

}
